(function() {
  var $, getDate, pad;
  $ = jQuery;
  pad = function(value, length) {
    var result;
    result = value.toString();
    while (result.length < length) {
      result = '0' + result;
    }
    return result;
  };
  getDate = function() {
    var now;
    now = new Date();
    now.setDate(now.getDate() - 2);
    return pad(now.getUTCFullYear(), 4) + '-' + pad(now.getUTCMonth() + 1, 2) + '-' + pad(now.getUTCDate(), 2);
  };
  $.fn.feedburner = function(options) {
    var settings;
    settings = $.extend({}, options);
    return this.each(function() {
      var callback, date, endpoint, link;
      link = $(this);
      date = getDate();
      endpoint = "http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=" + (link.attr('href')) + "&dates=" + date;
      callback = function(response) {
        var readersCount;
        readersCount = (response.documentElement.getElementsByTagName('entry'))[0].getAttribute('circulation');
        return link.attr('title', "" + readersCount + " readers");
      };
      return $.get(settings.url, {
        url: endpoint
      }, callback, 'xml');
    });
  };
}).call(this);
